/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PageSetupPanel.java
 *
 * Created on Oct 8, 2010, 10:36:48 AM
 */
package project.jpdftools.documentinfo.ui;

import java.awt.Toolkit;
import java.util.logging.Level;
import javax.swing.JDialog;
import project.jpdftools.documentinfo.DocumentInfo;
import project.jpdftools.managers.LocalizationManager;
import project.jpdftools.managers.LoggerManager;

/**
 *
 * @author Mido
 */
public class DocumentInfoUI extends JDialog {

    private static boolean is_component_visible = false;

    /**
     * Creates new form PageSetupPanel
     */
    public DocumentInfoUI() {
        // check if the frame is already visible
        if (is_component_visible == false) {
            initComponents();

            // center the component
            project.jpdftools.toolkit.Toolkit.centerWindow(this, this.getHeight(), this.getWidth());
            this.setAlwaysOnTop(true);

            // load previously saved values
            loadParameters();
            // indicate that the frame is visible
            is_component_visible = true;
            LoggerManager.getLogger().log(Level.INFO, "Frame shown \"{0}\".", "DocumentInfoUI");
        }
    }

    /**
     * Load previously saved parameters
     */
    private void loadParameters() {
        // load the values from the DocumentInfo class
        tf_title.setText(DocumentInfo.getTitle());
        tf_author.setText(DocumentInfo.getAuthor());
        tf_subject.setText(DocumentInfo.getSubject());
        tf_keywords.setText(DocumentInfo.getKeywords());
    }

    public static boolean IsComponentVisible() {
        return is_component_visible;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bt_ok = new javax.swing.JButton();
        bt_cancel = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        tf_title = new javax.swing.JTextField();
        l_subject = new javax.swing.JLabel();
        l_keywords = new javax.swing.JLabel();
        l_author = new javax.swing.JLabel();
        tf_subject = new javax.swing.JTextField();
        tf_author = new javax.swing.JTextField();
        l_title = new javax.swing.JLabel();
        tf_keywords = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(LocalizationManager.getCurrent_resource().getString("MAIN_MENU_DOCUMENT_INFO"));
        setIconImage(Toolkit.getDefaultToolkit().getImage("Data/Icons/Soft Scraps Icons/10.png"));
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                DocumentInfoUI.this.windowClosing(evt);
            }
        });

        bt_ok.setText(LocalizationManager.getCurrent_resource().getString("OK"));
        bt_ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_okActionPerformed(evt);
            }
        });

        bt_cancel.setText(LocalizationManager.getCurrent_resource().getString("CANCEL"));
        bt_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_cancelActionPerformed(evt);
            }
        });

        l_subject.setText("Subject:");

        l_keywords.setText("Keywords:");

        l_author.setText("Author:");

        l_title.setText("Title:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(l_title)
                    .addComponent(l_author)
                    .addComponent(l_keywords)
                    .addComponent(l_subject))
                .addGap(4, 4, 4)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tf_title, javax.swing.GroupLayout.PREFERRED_SIZE, 290, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tf_author, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tf_subject, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tf_keywords, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {tf_author, tf_keywords, tf_subject, tf_title});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(tf_title, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(l_title))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(tf_author, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(l_author))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(tf_subject, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(l_subject))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(tf_keywords, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(l_keywords))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {tf_author, tf_keywords, tf_subject, tf_title});

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(bt_cancel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(bt_ok)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_ok)
                    .addComponent(bt_cancel))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bt_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_cancelActionPerformed
        // close the frame
        this.dispose();
        // indicate that the frame is hidden
        is_component_visible = false;
        LoggerManager.getLogger().log(Level.INFO, "Frame hidden \"{0}\".", "DocumentInfoUI");
    }//GEN-LAST:event_bt_cancelActionPerformed

    private void bt_okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_okActionPerformed
        // save the values to the document Properties class
        DocumentInfo.setTitle(tf_title.getText());
        DocumentInfo.setAuthor(tf_author.getText());
        DocumentInfo.setSubject(tf_subject.getText());
        DocumentInfo.setKeywords(tf_keywords.getText());

        // close the frame
        this.dispose();
        // indicate that the frame is hidden
        is_component_visible = false;
        LoggerManager.getLogger().log(Level.INFO, "Document info changed.");
    }//GEN-LAST:event_bt_okActionPerformed

    private void windowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_windowClosing
        bt_cancelActionPerformed(null);
}//GEN-LAST:event_windowClosing
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_cancel;
    private javax.swing.JButton bt_ok;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel l_author;
    private javax.swing.JLabel l_keywords;
    private javax.swing.JLabel l_subject;
    private javax.swing.JLabel l_title;
    private javax.swing.JTextField tf_author;
    private javax.swing.JTextField tf_keywords;
    private javax.swing.JTextField tf_subject;
    private javax.swing.JTextField tf_title;
    // End of variables declaration//GEN-END:variables
}
